const { CustomerComments } = require('../models/customerCommentsModel')

//新增用户评价
async function addUserComments(req, res) {
    const { usersID='5f9e72c69d182c3b4ca6ad40', userID='5f9e797a9d182c3b4ca6ad46', score, content, ratingTime } = req.body;
    const data = await CustomerComments.create({ usersID, userID, score, content, ratingTime });
    try {
        if (data) {
            res.send({
                status: 1,
                msg: '新增成功',
                data,
            })
        }
    } catch (error) {   
        console.log('error', error);
    }
}
//获取所有用户评价
async function getUserComments(req,res){
    const data = await CustomerComments
    .find()
    .populate('userID')
    .populate('userID')
    try {
       if(data){
           res.send({
               status:1,
               msg:'获取成功',
               data
           })
       }
    } catch (error) {
        console.log("error",error)
    }
}
//删除
async function deletComments(req,res){
    const _id = req._id
    const data = await CustomerComments.deleteOne(_id)
        try {
            res.send({
                status:1,
                msg:"删除成功",
                data
            })
        } catch (error) {
            console.log("error",error)
        }
}
module.exports = { addUserComments ,getUserComments,deletComments};